# Contributor: @ifurther <55025025+ifurther@users.noreply.github.com>

_realname=hugo
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.147.5
pkgrel=1
pkgdesc='A Fast and Flexible Static Site Generator built with love by bep, spf13 and friends in Go. (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://gohugo.io/'
msys2_repository_url='https://github.com/gohugoio/hugo/'
msys2_references=(
  'archlinux: hugo'
  "cpe: cpe:/a:gohugo:hugo"
)
license=('spdx:Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-go" "${MINGW_PACKAGE_PREFIX}-cc" "git")
optdepends=("git: To interact with repositories")
options=('!strip')
source=("https://github.com/gohugoio/hugo/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('1decbe0a09065398c81810ddf929eaacf9747bf7bf9bd2acb795c2394c5c5dc8')

build() {
    cd "${_realname}-${pkgver}"
    export GOOS=windows
    export GOROOT=${MINGW_PREFIX}/lib/go
    export CGO_CPPFLAGS="${CPPFLAGS}"
    export CGO_CFLAGS="${CFLAGS}"
    export CGO_CXXFLAGS="${CXXFLAGS}"
    export CGO_LDFLAGS="${LDFLAGS}"
    export GO_LDFLAGS="-s -w"
    export GOFLAGS="-trimpath -mod=readonly -modcacherw -ldflags=-linkmode=external"

    go build -tags extended

    ./hugo.exe gen man
    ./hugo.exe completion bash > hugo.bash-completion
    ./hugo.exe completion fish > hugo.fish
    ./hugo.exe completion zsh > hugo.zsh
}

check() {
    cd "${_realname}-${pkgver}"
    go test
}

package() {
    cd "${_realname}-${pkgver}"
    install -Dm755 "hugo.exe" "${pkgdir}${MINGW_PREFIX}/bin/hugo.exe"
    install -Dm644 "LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
    install -Dm644 "README.md" "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/README.md"

    install -Dm644 man/*.1  -t "${pkgdir}${MINGW_PREFIX}"/share/man/man1/

    install -Dm644 hugo.bash-completion "${pkgdir}${MINGW_PREFIX}"/share/bash-completion/completions/hugo
    install -Dm644 hugo.fish "${pkgdir}${MINGW_PREFIX}"/share/fish/vendor_completions.d/hugo.fish
    install -Dm644 hugo.zsh "${pkgdir}${MINGW_PREFIX}"/share/zsh/site-functions/_hugo
}
